﻿using System;
using StartupToolsetInterfaces;

namespace MyCompany.StartupToolsetRefactored
{
  public sealed class CalculationService: ICalculationService, SCalculationService
  {
    public bool Calculate(string firstArgText, string secondArgText, 
      string operatorText, out string resultText)
    {
      try
      {
        int firstArg = Int32.Parse(firstArgText);
        int secondArg = Int32.Parse(secondArgText);
        int result = 0;
        switch (operatorText)
        {
          case "+":
            result = firstArg + secondArg;
            break;
          case "-":
            result = firstArg - secondArg;
            break;
          case "*":
            result = firstArg * secondArg;
            break;
          case "/":
            result = firstArg / secondArg;
            break;
          case "%":
            result = firstArg % secondArg;
            break;
        }
        resultText = result.ToString();
      }
      catch (SystemException)
      {
        resultText = "#Error";
        return false;
      }
      return true;
    }
  }
}
